home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Applications / Moscow ML 1.31 / source code / mosml / src / mosmllib / Miscoldb.sml < prev    next >
Encoding:
Text File  |  1996-07-03  |  1.9 KB  |  73 lines  |  [TEXT/R*ch]

  1. (* Miscoldb.sml 1995-02-24 -- upwards compatibility with Definition *)
  2.  
  3. fun (g o f) x = g (f x);
  4. fun a before (b : unit) = a;
  5.  
  6. (* The definitions below implement the requirement that units
  7.    Char, String and List are partially opened in the initial environment.
  8.  *)
  9.  
  10. prim_val chr : int    -> string = 1 "sml_chr";
  11. prim_val ord : string -> int    = 1 "sml_ord";
  12.  
  13. local 
  14.     prim_val create_string_ : int -> string                = 1 "create_string";
  15.     prim_val nth_char_      : string -> int -> int         = 2 "get_nth_char";
  16.     prim_val set_nth_char_  : string -> int -> int -> unit = 3 "set_nth_char";
  17.     prim_val blit_string_   : string -> int -> string -> int -> int -> unit 
  18.                                                            = 5 "blit_string";
  19.  
  20.     open String
  21. in 
  22.     fun explode s =
  23.     let fun loop 0 acc = acc
  24.           | loop n acc =
  25.         let val n' = n - 1
  26.             val x = create_string_ 1
  27.         in
  28.             set_nth_char_ x 0 (nth_char_ s n');
  29.             loop n' (x::acc)
  30.         end
  31.     in loop (size s) [] end;
  32.  
  33.     fun implode ss =
  34.     let fun resultSizeAcc [] acc = acc
  35.           | resultSizeAcc (s::ss) acc = resultSizeAcc ss (acc + size s)
  36.         val rlen = resultSizeAcc ss 0
  37.         val r = create_string_ rlen
  38.         fun loop [] i = ()
  39.           | loop (s::ss) i =
  40.         let val slen = size s in
  41.             blit_string_ s 0 r i slen;
  42.             loop ss (i + slen)
  43.         end
  44.     in loop ss 0; r end;
  45. end;
  46.  
  47. val concat = String.concat;
  48. val str = String.str;
  49.  
  50. exception Empty = List.Empty;
  51. val op @ = List.@;
  52. val app = List.app;
  53. val foldl = List.foldl;
  54. val foldr = List.foldr;
  55. val hd = List.hd;
  56. val length = List.length;
  57. val map = List.map;
  58. val null = List.null;
  59. val rev = List.rev;
  60. val tl = List.tl;
  61.  
  62. val vector = Vector.fromList;
  63.  
  64. exception Abs   = Overflow
  65.       and Diff  = Overflow
  66.       and Exp   = Overflow
  67.       and Floor = Overflow
  68.       and Neg   = Overflow
  69.       and Prod  = Overflow
  70.       and Sum   = Overflow
  71.       and Quot  = Overflow
  72.       and Mod   = Div;
  73.